home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 April / april_2001.iso / intercd / root / ^Palm / Games / eCross / src / Exit.java < prev    next >
Encoding:
Java Source  |  2000-08-01  |  3.3 KB  |  123 lines

  1. /*
  2.  * Exit.java - Provides an exit button
  3.  * eCross is Copyright (C) 2000 Romain Guy
  4.  * guy.romain@bigfoot.com
  5.  * www.jext.org
  6.  *
  7.  * This program is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU General Public License
  9.  * as published by the Free Software Foundation; either version 2
  10.  * of the License, or any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  */
  21.  
  22. import waba.fx.*;
  23.  
  24. /**
  25.  * A control that displays an exit button
  26.  * @version 1.0
  27.  * @author Romain Guy <guy.romain@bigfoot.com>
  28.  */
  29.  
  30. public class Exit extends Bounded
  31. {
  32.   private byte state = 0;
  33.   private Image exitImage = new Image("datas/exit.bmp");
  34.  
  35.   /**
  36.    * Creates a new exit button.
  37.    */
  38.  
  39.   public Exit() { }
  40.  
  41.   /**
  42.    * Handles a pen down event.
  43.    * @param parent The caller
  44.    * @param g The <code>Graphics</code> surface of the caller
  45.    * @param x The x coordinate of the event
  46.    * @param y The y coordinate of the event
  47.    * @return <code>true</code> if the event was handled
  48.    */
  49.  
  50.   public boolean handlePenEvent(eCross parent, Graphics g, int x, int y)
  51.   {
  52.     if (state == 0)
  53.     {
  54.       if (x > this.x && x < (this.x + this.width) &&
  55.           y > this.y && y < (this.y + this.height))
  56.       {
  57.         parent.pauseTimer();
  58.  
  59.         g.setColor(255, 255, 255);
  60.         // erase place of the window
  61.         g.fillRect(19, 59, 122, 42);
  62.         /////////////////////////////////////////
  63.         // we should erase grid informations here
  64.  
  65.         g.setColor(0, 0, 0);
  66.         g.drawRect(20, 60, 120, 40);
  67.  
  68.         Font font = new Font("Helvetica", Font.BOLD, 10);
  69.         g.setFont(font);
  70.         FontMetrics fm = parent.getFontMetrics(font);
  71.         String text = new String("Really quit eCross ?");
  72.         g.drawText(text, (160 - fm.getTextWidth(text)) / 2, 65);
  73.  
  74.         g.drawRect(48, 80, 30, 15);
  75.         g.drawDots(50, 95, 78, 95);
  76.         g.drawDots(78, 94, 78, 82);
  77.         text = new String("Yes");
  78.         g.drawText(text, 48 + (30 - fm.getTextWidth(text)) / 2, 82);
  79.  
  80.         g.drawRect(82, 80, 30, 15);
  81.         g.drawDots(84, 95, 112, 95);
  82.         g.drawDots(112, 94, 112, 82);
  83.         text = new String("No");
  84.         g.drawText(text, 82 + (30 - fm.getTextWidth(text)) / 2, 82);
  85.  
  86.         state = 1;
  87.  
  88.         return true;
  89.       }
  90.     } else if (state == 1) {
  91.  
  92.       // click on yes
  93.       if (x > 48 && x < 78 &&
  94.           y > 80 && y < 95)
  95.       {
  96.         parent.exit(0);
  97.       } else if (x > 82 && x < 112 &&
  98.                  y > 80 && y < 95)
  99.       {
  100.         state = 0;
  101.         parent.draw();
  102.         parent.resumeTimer();
  103.       }
  104.  
  105.       return true;
  106.     }
  107.  
  108.     return false;
  109.   }
  110.  
  111.   public void paint(Graphics g)
  112.   {
  113.     g.setColor(255, 255, 255);
  114.     g.fillRect(x, y, width, height);
  115.     g.setColor(0, 0, 0);
  116.     g.drawRect(x, y, width, height);
  117.  
  118.     g.drawImage(exitImage, x + 2, y + 2);
  119.   }
  120. }
  121.  
  122. // End of Exit.java
  123.